using Middleware;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

/*
app.MapGet("/", () => "Hello World!");
app.MapGet("/test", () => "Hello Michael!");
*/

app.Map("/Index", async (pipeBuilder) =>
{
    pipeBuilder.UseMiddleware<CheckMiddleware>();
    pipeBuilder.Use(async (context, next) =>
    {
        context.Response.ContentType = "text/html";
        await context.Response.WriteAsync("1 start<br/>");
        await next.Invoke();
        await context.Response.WriteAsync("1 end<br/>");
    });

    pipeBuilder.Use(async (context, next) =>
    {
        await context.Response.WriteAsync("2 start<br/>");
        await next.Invoke();
        await context.Response.WriteAsync("2 end<br/>");
    });

    pipeBuilder.UseMiddleware<Test1Middleware>();
    pipeBuilder.Run(async (context) =>
    {
        await context.Response.WriteAsync("Run<br/>");
        dynamic obj = context.Items["BodyJson"];
        if (obj != null)
        {
            await context.Response.WriteAsync($"{obj}" + "<br/>");
        }
    });
 });
app.Run();
